home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6984 / 6984.xpi / chrome / lazarus.jar / content / text-recover.js < prev    next >
Text File  |  2009-11-24  |  4KB  |  103 lines

  1.  
  2.  
  3. Lazarus.getString = Lazarus.getBrowser().Lazarus.getString;
  4. Lazarus.db = Lazarus.getBrowser().Lazarus.db;
  5. Lazarus.decrypt = Lazarus.getBrowser().Lazarus.decrypt;
  6.  
  7. LazarusTextRecover = {
  8.     
  9.     init: function(){
  10.         var errMsg = ''
  11.         window.removeEventListener("load", LazarusTextRecover.init, true);
  12.                 var id = Lazarus.getUrlQuery(window.location.href, 'id');
  13.                 var table = Lazarus.getUrlQuery(window.location.href, 'table');
  14.                 
  15.                 if (!id){
  16.                     errMsg = Lazarus.getString('LazarusTextRecover.noIdGiven');    
  17.                 }
  18.         //load the text
  19.                 else if (table == "textdata"){
  20.             var text = Lazarus.decrypt(Lazarus.db.getStr("SELECT text_encrypted FROM textdata WHERE id = ?1", id));
  21.             if (text){
  22.                 Lazarus.$('text').value = text;
  23.                 Lazarus.$('iframe').contentWindow.document.body.innerHTML = text;
  24.                 if (!text.match(/<\w+/)){
  25.                     //hide the html tab
  26.                     //hmmm hiding just the one tab makes the next tab look silly (bits are missing from the side)
  27.                     //Lazarus.$('tab-html').hidden = true;
  28.                     //so we're going to hide all the tabs instead.
  29.                     Lazarus.$('tabs').hidden = true;
  30.                     Lazarus.$('tabbox').selectedTab = Lazarus.$('tab-text');
  31.                 }
  32.             }
  33.             else {
  34.                 errMsg = Lazarus.getString('LazarusTextRecover.textNotFound');
  35.             }
  36.         }
  37.                 else if (table == "forms"){
  38.                         var json = Lazarus.decrypt(Lazarus.db.getStr("SELECT forminfo FROM forms WHERE id = ?1", id));
  39.                         
  40.             if (json){
  41.                                 //decode the forminfo json object
  42.                                 var forminfo = Lazarus.JSON.decode(json);
  43.                                 
  44.                                 if (forminfo){
  45.                                     var text = forminfo.formtext;
  46.                                     Lazarus.$('text').value = text;
  47.                                     Lazarus.$('iframe').contentWindow.document.body.innerHTML = text;
  48.                                     if (!text.match(/<\w+/)){
  49.                                             //hide the html tab
  50.                                             //hmmm hiding just the one tab makes the next tab look silly (bits are missing from the side)
  51.                                             //Lazarus.$('tab-html').hidden = true;
  52.                                             //so we're going to hide all the tabs instead.
  53.                                             Lazarus.$('tabs').hidden = true;
  54.                                             Lazarus.$('tabbox').selectedTab = Lazarus.$('tab-text');
  55.                                     }
  56.                                 }
  57.                                 else {
  58.                                     errMsg = Lazarus.getString('error.form.db.corrupt');
  59.                                 }
  60.             }
  61.             else {
  62.                 errMsg = Lazarus.getString('LazarusTextRecover.textNotFound');
  63.             }
  64.                 }
  65.         else {
  66.                     errMsg = Lazarus.getString('LazarusTextRecover.noTableGiven');    
  67.         }
  68.         
  69.         if (errMsg){
  70.             setTimeout(function(){
  71.                 alert(errMsg);
  72.                 window.close();
  73.             }, 1);
  74.         }
  75.     },
  76.     
  77.     copyToClipboard: function(){
  78.         
  79.         try {
  80.             //if the user is looking at the source view, then we need to only copy the plain text
  81.             if (Lazarus.$('tabbox').selectedTab == Lazarus.$('tab-text')){
  82.                 Lazarus.Clipboard.setText(Lazarus.$('text').value)
  83.             }
  84.             else {
  85.                 Lazarus.Clipboard.setHTML(Lazarus.$('iframe').contentWindow.document.body.innerHTML);
  86.             }
  87.             window.close();
  88.         }
  89.         catch(e){
  90.             alert(Lazarus.getString("LazarusTextRecover.copyToClipboardFailed"));
  91.         }
  92.     },
  93.     
  94.     
  95.     doCommand: function(cmd, event){
  96.         //make sure the focus is set to the right element                               
  97.         var controller = document.commandDispatcher.getControllerForCommand(cmd);
  98.         controller.doCommand(cmd);
  99.         event.stopPropagation();
  100.     }
  101. }
  102.  
  103. window.addEventListener("load", LazarusTextRecover.init, true);